<template>
    <el-container class="home-container">
        <el-header>
            <div>
                <img src="@/assets/my-logo.png" alt="" height="40px" width="40px" class="logo">
                <span>飞凡空间后台管理</span>
            </div>
            <el-button type="info" @click="logout"><b>退 出</b></el-button></el-header>
        <el-container>
            <el-aside :width="isCollapse ? '64px' : '200px'">
              <div class="toggle-button" @click="toggleCooapse"> | | |</div>
              <el-menu background-color="#333744" text-color="white" 
              active-text-color="#409EFF" 
              unique-opened 
              :collapse="isCollapse"
              :collapse-transition="false"
              router
              :default-active="$route.path"
              >
                <el-submenu :index="items.id + ''" v-for="items in menuList" :key="items.id">
                    <template slot="title">
                    <i :class="icons[items.order]"></i>
                    <span>{{items.name}}</span>
                    </template>
                    <el-menu-item :index="'/' + item.path" v-for="item in items.children" :key="item.id">
                        <template slot="title">
                            <i class="el-icon-menu"></i>
                            {{item.name}}
                        </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data(){
        return {
            menuList: [],
            icons :{
                "1":'iconfont icon-user',
                "2":"iconfont icon-tijikongjian",
                "3":'iconfont icon-shangpin',
                "4":'iconfont icon-danju',
                "5":"iconfont icon-baobiao",
            },
            isCollapse: false,
            avtivePath: '',
        }
    },
    created(){
        this.getMenuList();
    },
    methods: {
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login");
        },
        async getMenuList(){
            const {data: res, status: status} = await this.axios.get("menus")
            if (status === 200) {
                this.menuList = res.data;
            }else if(status >= 250) {
                this.$router.push("/login");
            }else{
                this.$message.error(res.msg);
            }
        },
        toggleCooapse(){
            this.isCollapse = !this.isCollapse;
        },
    }
}
</script>
<style lang="less" scoped>
.logo{
    border-radius: 50%;
    margin-left: 20px;
}
.home-container{
    height: 100%;
}
.el-header{
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: white;
    font-size: 20px;
     background-color: #373d41;
    > div{
        display: flex;
        align-items: center;
        span{
           margin-left: 15px;
        }
    }
}

.el-aside{
    background-color: #333744;
    .el-menu{
        border-right: none;
    }
}
.el-main{
    background-color: #eaedf1;
}

.iconfont{
    margin-right: 10px;
}

.toggle-button{
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: white;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>